package com.hdsx.restful.glzt.roadline.lxxx.rest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.wink.common.annotations.Workspace;
import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.interop.AutomationException;
import com.hdsx.ao.util.StringUtile;
import com.hdsx.restful.base.PreparedDataListener;
import com.hdsx.restful.dist.service.IDistService;
import com.hdsx.restful.glzt.roadline.cdsl.service.CdslService;
import com.hdsx.restful.glzt.roadline.jsdj.service.JsdjService;
import com.hdsx.restful.glzt.roadline.ldmclx.service.LdmclxService;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Line;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Lx;
import com.hdsx.restful.glzt.roadline.lxxx.bean.LxAreaDetail;
import com.hdsx.restful.glzt.roadline.lxxx.bean.LxDetail;
import com.hdsx.restful.glzt.roadline.lxxx.bean.LxStatisticalDetail;
import com.hdsx.restful.glzt.roadline.lxxx.bean.LxdmMapLxmc;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Xzqh;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.roadline.lxxx.service.LxPoadPosLonLatService;
import com.hdsx.restful.glzt.roadline.lxxx.service.LxService;
import com.hdsx.restful.glzt.roadline.nclx.service.INclxService;
import com.hdsx.restful.glzt.roadline.xzqh.service.XzqhService;
import com.hdsx.restful.glzt.structure.crk.service.CrkServer;
import com.hdsx.restful.glzt.structure.fwq.service.FwqServer;
import com.hdsx.restful.glzt.structure.jkss.service.JkssService;
import com.hdsx.restful.glzt.structure.jtlgcz.service.JtlgczServer;
import com.hdsx.restful.glzt.structure.kbqbb.service.KbqbbServer;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.glzt.structure.ql.service.QlServer;
import com.hdsx.restful.glzt.structure.sd.service.SdServer;
import com.hdsx.restful.glzt.structure.sfz.service.SfzServer;
import com.hdsx.restful.glzt.structure.zcz.service.ZczServer;
import com.hdsx.restful.util.CheckEmpty;
import com.hdsx.restful.util.Constant;
import com.hdsx.restful.util.EasyUI;

// TODO: Auto-generated Javadoc
/**
 * The Class LxRestService.
 */
@Workspace(workspaceTitle = "restful", collectionTitle = "lxxx") 
@Path("/lxxx")
@Service
public class LxRestService {
		@Resource(name="nclxServiceImpl")
		private INclxService nclxService;
	
		@Resource(name="distServiceImpl")
		private IDistService distService;
		/** The lx server. */
		@Resource(name="lxServiceImpl")
		private LxService lxService;
		
		@Resource(name="jsdjServiceImpl")
		private JsdjService jsdjService;
		
		@Resource(name="cdslServiceImpl")
		private CdslService cdslService;
		
		@Resource(name="xzqhServiceImpl")
		private XzqhService xzqhService;
		
		@Resource(name="ldmclxServiceImpl")
		private LdmclxService mclxService;
		
		@Resource(name="crkServerImpl")
		private CrkServer crkServer;
		
		@Resource(name="fwqServerImpl")
		private FwqServer fwqServer;
		
		@Resource(name="jkssServiceImpl")
		private JkssService jkssService;
		
		@Resource(name="jtlgczServerImpl")
		private JtlgczServer jtlgczServer;
		
		@Resource(name="kbqbbServerImpl")
		private KbqbbServer kbqbbServer;
		
		@Resource(name="qlServerImpl")
		private QlServer qlServer;
		
		@Resource(name="sdServerImpl")
		private SdServer sdServer;
		
		@Resource(name="sfzServerImpl")
		private SfzServer sfzServer;
		
		@Resource(name="zczServerImpl")
		private ZczServer zczServer;
		
		/** The lx poad pos lon lat service. */
		@Resource(name="lxPoadPosLonLatServiceImpl")
		private LxPoadPosLonLatService lxPoadPosLonLatService;
		
	/**
	 * Gets the list.
	 *
	 * @param xzqhbm the xzqhbm
	 * @param lxdm the lxdm
	 * @param page the page
	 * @param rows the rows
	 * @return the list
	 * http://192.168.0.103:8080/restful/rest/lxxx/queryByParameter?xzqhbm=610581&lxdm=H108&page=0&rows=10
	 */
	@GET
	@Path("/queryByParameter")
	@Produces(MediaType.APPLICATION_JSON)
	public  EasyUI<Xzqh> queryListByParameter(@QueryParam("xzqhbm") String xzqhbm,
			@QueryParam("lxdm") String lxdm,@QueryParam("page") int page,@QueryParam("rows") int rows)
	{	

		EasyUI<Xzqh> uiPage = new EasyUI<Xzqh>(page, rows);
		int count =lxService.queryLxCountByParameter(xzqhbm,lxdm);
		List<Xzqh> servicefws= lxService.queryLxByParameter(xzqhbm,lxdm,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(servicefws);
		return uiPage;
	}
	
	
	/**
	 * http://192.168.0.103:8080/restful/rest/lxxx/list?lxdm=H108
	 *
	 * @param lxdm the lxdm
	 * @return the list< lx>
	 */
	@GET
	@Path("/list")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> queryLxBylxdm(@QueryParam("lxdm") String lxdm,@QueryParam("name")String name)
	{
		List<Lx> lxs= lxService.queryList(lxdm);
		return lxs;
	}
	
	/**
	 * 192.168.0.103:8080/restful/rest/lxxx/queryByLxmc?lxmc=京昆线
	 *
	 * @param lxmc the lxmc
	 * @param page the page
	 * @param rows the rows
	 * @return the easy u i< lx>
	 */
	@GET
	@Path("/queryByLxmc")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Lx> queryByLxmc(@QueryParam("lxmc") String lxmc,@QueryParam("page") int page,@QueryParam("rows") int rows)
	{
		EasyUI<Lx> uiPage = new EasyUI<Lx>(page, rows);
		int count =lxService.queryLxCountByLxmc(lxmc);
		List<Lx> servicefws= lxService.queryLxByLxmc(lxmc,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(servicefws);
		return uiPage;
	}
	
	/*
	 * http://192.168.0.103:8080/restful/rest/lxxx/queryByXzqhbm?xzqhbm=610581
	 */
	/**
	 * Query by xzqhbm.
	 *
	 * @param xzqhbm the xzqhbm
	 * @param page the page
	 * @param rows the rows
	 * @return the easy u i< xzqh>
	 */
	@GET
	@Path("/queryByXzqhbm")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Xzqh> queryByXzqhbm(@QueryParam("xzqhbm") String xzqhbm,@QueryParam("page") int page,@QueryParam("rows") int rows)
	{
		EasyUI<Xzqh> uiPage = new EasyUI<Xzqh>(page, rows);
		int count =lxService.queryLxCountByXzqhbm(xzqhbm);
		List<Xzqh> servicefws= lxService.queryLxByXzqhbm(xzqhbm,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(servicefws);
		return uiPage;
	}
	
	/*
	 * http://192.168.0.103:8080/restful/rest/lxxx/info?id=9611d39c-19f3-415c-9c36-6a7cf8d603c5
	 */
	/**
	 * Query line string.
	 *
	 * @param id the id
	 * @return the string
	 */
	@GET
	@Path("/info")
	@Produces(MediaType.APPLICATION_JSON)
	public String queryLineString(@QueryParam("id") String id)
	{
		return lxService.queryLine(id);
	}

	/**
	 * Query line.
	 *
	 * @param id the id
	 * @return the string
	 */
	@GET
	@Path("/info1")
	@Produces(MediaType.APPLICATION_JSON)
	public String queryLine(@QueryParam("id") String id)
	{
		return lxService.queryLine(id);
	}
	
	/**
	 * 统计查询.
	 *
	 * @param lxdm the lxdm
	 * @return the list< lx>
	 */
	@GET
	@Path("/statisticsJsdjByLxdm")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> statisticsJsdjByLxdm(@QueryParam("lxdm") String lxdm)
	{
		return lxService.statisticsJsdjByLxdm(lxdm);
	}
	
	/**
	 * 统计查询.
	 *
	 * @param xzqhbm the xzqhbm
	 * @return the list< lx>
	 */
	@GET
	@Path("/statisticsJsdjByXzqhbm")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> statisticsJsdjByXzqhbm(@QueryParam("xzqhbm") String xzqhbm)
	{
		return lxService.statisticsJsdjByXzqhbm(xzqhbm);
	}
	
	
	/**
	 * 统计查询.
	 *
	 * @param xzqhbm the xzqhbm
	 * @return the list< lx>
	 */
	@GET
	@Path("/statisticsJsdjByXzqhbm")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> statisticsXzdjByXzqhbm(@QueryParam("xzqhbm") String xzqhbm)
	{
		return lxService.statisticsXzdjByXzqhbm(xzqhbm);
	}
	
	/**
	 * 统计查询.
	 *
	 * @param lxdm the lxdm
	 * @return the list< lx>
	 */
	@GET
	@Path("/statisticsCdtzByLxdm")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> statisticsCdtzByLxdm(@QueryParam("lxdm") String lxdm)
	{
		return lxService.statisticsCdtzByLxdm(lxdm);
	}
	
	/**
	 * 统计查询.
	 *
	 * @param xzqhbm the xzqhbm
	 * @return the list< lx>
	 */
	@GET
	@Path("/statisticsCdtzByXzqhbm")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Lx> statisticsCdtzByXzqhbm(@QueryParam("xzqhbm") String xzqhbm)
	{
		return lxService.statisticsCdtzByXzqhbm(xzqhbm);
	}
	
	/**
	 * 路线统计.
	 *
	 * @param szlx the szlx
	 * @param xzqhbm the xzqhbm
	 * @param type the type
	 * @return the statistical result
	 */
	@GET
	@Path("/tjjg")
	@Produces(MediaType.APPLICATION_JSON)
	public StatisticalResult getStatisticalResult(@QueryParam("szlx") String szlx, @QueryParam("xzqhbm") String xzqhbm,@QueryParam("type") String type){
		
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxdm", szlx);
		map.put("type", type);
		map.put("xzqhbm", xzqhbm);
		StatisticalResult tjjg  = new StatisticalResult();
		if("2".equals(type)){
			tjjg = lxService.countLxByParameter(map);
		}else if(!StringUtile.isEmptyStr(type)){
			tjjg = lxService.countLdByParameter(map);
		}
		return tjjg;
	}
	
	/**
	 * 联想输入.
	 *
	 * @param lxdm the lxdm
	 * @param lxmc the lxmc
	 * @return the list< lxdm map lxmc>
	 */
	@GET
	@Path("/like")
	@Produces(MediaType.APPLICATION_JSON)
	public List<LxdmMapLxmc> like(@QueryParam("lxdm") String dm, @QueryParam("lxmc") String mc){
		Lx lx = new Lx();
		lx.setLxdm(dm);
		lx.setLxmc(mc);
		List<LxdmMapLxmc> results = lxService.selectResultsByParameter(dm, mc);
		List<LxdmMapLxmc> results2 = nclxService.selectResultsByParameter(dm, mc);
		results.addAll(results2);
		return results;
//		return PreparedDataListener.getLxmcs();
	}
	
	/**
	 * 行政等级树.
	 *
	 * @return the list< znode>
	 */
	@GET
	@Path("/xzdjNode")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Znode> tree(){
		List<Znode> xzdjNode = PreparedDataListener.getData("lx");
		return xzdjNode;
	}
	
	
	
	
	/**
	 * 坐标转桩号.
	 *
	 * @param lxdm the lxdm
	 * @param qdzh the qdzh
	 * @param zdzh the zdzh
	 * @param ptx the ptx
	 * @param pty the pty
	 * @return the string
	 */
	@GET
	@Path("PosByLonLat")
	@Produces(MediaType.TEXT_PLAIN)
	public String PosByLonLat(@QueryParam("lxdm") String lxdm,@QueryParam("qdzh") double qdzh,@QueryParam("zdzh") double zdzh,@QueryParam("ptx") double ptx,@QueryParam("pty") double pty){
			IPoint point=lxPoadPosLonLatService.posByLonLat(lxdm,qdzh,zdzh,ptx,pty);
			try {
				return "{x:"+point.getX()+",y:"+point.getY()+",m:"+point.getM()+"}";
			} catch (AutomationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
	}
	
	/**
	 * 桩号转坐标.
	 *
	 * @param lxdm the lxdm
	 * @param pos the pos
	 * @return the string
	 */
	@GET
	@Path("LonLatByRoadPos")
	@Produces(MediaType.TEXT_PLAIN)
	public String LonLatByRoadPos(@QueryParam("lxdm") String lxdm,@QueryParam("pos") double pos){
		IPoint point=lxPoadPosLonLatService.lonLatByRoadPos(lxdm,pos);
		try {
			return "{x:"+point.getX()+",y:"+point.getY()+",m:"+point.getM()+"}";
		} catch (AutomationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 坐标转桩号.
	 *
	 * @param lxdm the lxdm
	 * @param qdzh the qdzh
	 * @param zdzh the zdzh
	 * @return the segment
	 */
	@GET
	@Path("segment")
	@Produces(MediaType.TEXT_PLAIN)
	public String  getSegment(@QueryParam("lxdm") String lxdm,@QueryParam("qdzh") double qdzh,@QueryParam("zdzh") double zdzh)
	{
		return lxPoadPosLonLatService.getSegment(lxdm, qdzh, zdzh);
	}
	
	/**
	 * Query sqh.
	 *
	 * @return the list< xzqh>
	 */
	@GET
	@Path("querySjXzqh")
	@Produces(MediaType.TEXT_PLAIN)
	public List<Xzqh> querySQH(){
		List<Xzqh> lists=lxService.querySQH();
		return lists;
	}
	
	/**
	 * Query xqh.
	 *
	 * @param xzqhbm the xzqhbm
	 * @param page the page
	 * @param rows the rows
	 * @return the easy u i< xzqh>
	 */
	@GET
	@Path("queryXjXzqh")
	@Produces(MediaType.TEXT_PLAIN)
	public EasyUI<Xzqh> queryXQH(@QueryParam("xzqhbm") String xzqhbm,@QueryParam("page") int page,
			@QueryParam("rows") int rows){
		
		EasyUI<Xzqh> uiPage = new EasyUI<Xzqh>(page, rows);
		int count =lxService.queryCountXQH(xzqhbm);
		List<Xzqh> lists=lxService.queryXQH(xzqhbm,page,rows);	 	
		uiPage.setTotal(count);
		uiPage.setRows(lists);
		return uiPage;
	}
	/**
	 * 桥梁，隧道，收费站，服务区，出入口，可变情报板，交通量观测站，监控摄像设备
	 * @param id
	 * @param type
	 * @return
	 */
	@GET
	@Path("/detail")
	@Produces(MediaType.APPLICATION_JSON)
	public LxDetail detail(@QueryParam("id")String id,@QueryParam("lxdm")String lxbm,@QueryParam("sxxfx")String sxxfx, 
			@QueryParam("qdzh")String qdzh_string, @QueryParam("zdzh")String zdzh_string,
			@QueryParam("xzqhbm")String xzqhbm,@QueryParam("type") String type,@QueryParam("page") int page,@QueryParam("rows") int rows){
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("没有输入qdzh和zdzh或者不是数字！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		Line parameter = new Line(id,lxbm, qdzh, zdzh, xzqhbm, sxxfx);
		LxDetail lxDetail = new LxDetail();
		Line line = new Line();
		List<LxAreaDetail> areas = new ArrayList<LxAreaDetail>();
		if(Constant.DM_JSDJ.equals(type)){
			line = jsdjService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = jsdjService.lxArea(parameter);
		}else if(Constant.DM_XZQH.equals(type)){
			line = xzqhService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = xzqhService.lxArea(parameter);
		}else if(Constant.DM_CDSL.equals(type)){
			line = cdslService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = cdslService.lxArea(parameter);
		}else if(Constant.DM_MCLX.equals(type)){
			line = mclxService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = mclxService.lxArea(parameter);
		}else if(Constant.DM_LXZB.equals(type)){
			line = lxService.ldDetail(parameter);
		}
		if(line == null) {
			System.out.println("该路线已经被删除！");
			return null;
		}
		lxDetail.setLine(line);
		lxDetail.setAreas(areas);
		if(!CheckEmpty.isEmptyString(line.getXzqhbm()))
			lxDetail.setArea(distService.selectNameByCode(line.getXzqhbm()));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxbm", line.getLxdm());
		map.put("sxxfx", line.getSxxfx());
		map.put("xzqhbm", line.getXzqhbm());
		map.put("qdzh", line.getQdzh());
		map.put("zdzh", line.getZdzh());
		lxDetail.setCrkNum(crkServer.countTotal(map));
		lxDetail.setFwqNum(fwqServer.countTotal(map));
		lxDetail.setJksxsbNum(jkssService.countTotal(map));
		lxDetail.setJtlgczNum(jtlgczServer.countTotal(map));
		lxDetail.setKbqbbNum(kbqbbServer.countTotal(map));
		lxDetail.setQlNum(qlServer.countTotal(map));
		lxDetail.setSdNum(sdServer.countTotal(map));
		lxDetail.setSfzNum(sfzServer.countTotal(map));
		lxDetail.setZczNum(zczServer.countTotal(map));
		return lxDetail;
	}
	
	@GET
	@Path("/pie")
	@Produces(MediaType.APPLICATION_JSON)
	public LxStatisticalDetail pie(@QueryParam("id")String id,@QueryParam("lxdm")String lxbm,@QueryParam("sxxfx")String sxxfx, 
			@QueryParam("qdzh")String qdzh_string, @QueryParam("zdzh")String zdzh_string,
			@QueryParam("xzqhbm")String xzqhbm,@QueryParam("type") String type){
		LxStatisticalDetail statisticalDetail = new LxStatisticalDetail();
		Line line = new Line();
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("没有输入qdzh和zdzh或者不是数字！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		List<LxAreaDetail> areas = new ArrayList<LxAreaDetail>();
		Line parameter = new Line(id,lxbm, qdzh, zdzh, xzqhbm, sxxfx);
		if(Constant.DM_JSDJ.equals(type)){
			line = jsdjService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = jsdjService.lxArea(parameter);
		}else if(Constant.DM_XZQH.equals(type)){
			line = xzqhService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = xzqhService.lxArea(parameter);
		}else if(Constant.DM_CDSL.equals(type)){
			line = cdslService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = cdslService.lxArea(parameter);
		}else if(Constant.DM_MCLX.equals(type)){
			line = mclxService.ldDetail(parameter);
			if(!CheckEmpty.isEmptyString(lxbm))
				areas = mclxService.lxArea(parameter);
		}else if(Constant.DM_LXZB.equals(type)){
			line = lxService.ldDetail(parameter);
		}
		if(line == null) {
			System.out.println("该路线已经被删除！");
			return null;
		}
		statisticalDetail.setLine(line);
		statisticalDetail.setAreas(areas);
		if(!CheckEmpty.isEmptyString(line.getXzqhbm()))
			statisticalDetail.setArea(distService.selectNameByCode(line.getXzqhbm()));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxdm", line.getLxdm());
		map.put("sxxfx", line.getSxxfx());
		map.put("xzqhbm", line.getXzqhbm());
		map.put("qdzh", line.getQdzh());
		map.put("zdzh", line.getZdzh());
		map.put("type", Constant.DM_JSDJ);
		StatisticalResult jsdj_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_CDSL);
		StatisticalResult cdsl_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_MCLX);
		StatisticalResult mclx_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_XZQH);
		StatisticalResult xzdj_tjjg = lxService.countLxByParameter(map);
		
		statisticalDetail.getTreePies().put("jsdj", jsdj_tjjg);
		statisticalDetail.getTreePies().put("cdsl", cdsl_tjjg);
		statisticalDetail.getTreePies().put("mclx", mclx_tjjg);
		statisticalDetail.getTreePies().put("xzdj", xzdj_tjjg);
		
		return statisticalDetail;
	}
	
	/**
	 * 桥梁，隧道，收费站，服务区，出入口，可变情报板，交通量观测站，监控摄像设备
	 * @param id
	 * @param type
	 * @return
	 */
	@GET
	@Path("/detailnext")
	@Produces(MediaType.APPLICATION_JSON)
	public LxDetail detailnext(@QueryParam("id")String id,@QueryParam("pid")String pid){
		LxDetail lxDetail = new LxDetail();
		
		Line parameter = new Line(id,pid);
		Line line = lxService.thirdnext(parameter);
		if(line == null) {
			System.out.println("该路线不存在！");
			return null;
		}
		Line line_ = new Line();
		try{
			PropertyUtils.copyProperties(line_, line);
			line_.setId(null);
		}catch(Exception e){
			e.printStackTrace();
			line_ = line;
		}
		Line ldDetail = jsdjService.ldDetail(line_);
		line.setQdmc(ldDetail.getQdmc());
		line.setZdmc(ldDetail.getZdmc());
		lxDetail.setArea(distService.selectNameByCode(line.getXzqhbm()));
		lxDetail.setLine(line);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxbm", line.getLxdm());
		map.put("sxxfx", line.getSxxfx());
		map.put("xzqhbm", line.getXzqhbm());
		map.put("qdzh", line.getQdzh());
		map.put("zdzh", line.getZdzh());
		lxDetail.setCrkNum(crkServer.countTotal(map));
		lxDetail.setFwqNum(fwqServer.countTotal(map));
		lxDetail.setJksxsbNum(jkssService.countTotal(map));
		lxDetail.setJtlgczNum(jtlgczServer.countTotal(map));
		lxDetail.setKbqbbNum(kbqbbServer.countTotal(map));
		lxDetail.setQlNum(qlServer.countTotal(map));
		lxDetail.setSdNum(sdServer.countTotal(map));
		lxDetail.setSfzNum(sfzServer.countTotal(map));
		lxDetail.setZczNum(zczServer.countTotal(map));
		return lxDetail;
	}
	
	@GET
	@Path("/pienext")
	@Produces(MediaType.APPLICATION_JSON)
	public LxStatisticalDetail pienext(@QueryParam("id")String id,@QueryParam("pid")String pid){
		LxStatisticalDetail statisticalDetail = new LxStatisticalDetail();
		
		Line parameter = new Line(id,pid);
		Line line = lxService.thirdnext(parameter);
		if(line == null) {
			System.out.println("该路线不存在！");
			return null;
		}
		statisticalDetail.setArea(distService.selectNameByCode(line.getXzqhbm()));
		statisticalDetail.setLine(line);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxdm", line.getLxdm());
		map.put("sxxfx", line.getSxxfx());
		map.put("xzqhbm", line.getXzqhbm());
		map.put("qdzh", line.getQdzh());
		map.put("zdzh", line.getZdzh());
		map.put("type", Constant.DM_JSDJ);
		StatisticalResult jsdj_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_CDSL);
		StatisticalResult cdsl_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_MCLX);
		StatisticalResult mclx_tjjg = lxService.countLdByParameter(map);
		map.put("type", Constant.DM_XZQH);
		StatisticalResult xzdj_tjjg = lxService.countLxByParameter(map);
		
		statisticalDetail.getTreePies().put("jsdj", jsdj_tjjg);
		statisticalDetail.getTreePies().put("cdsl", cdsl_tjjg);
		statisticalDetail.getTreePies().put("mclx", mclx_tjjg);
		statisticalDetail.getTreePies().put("xzdj", xzdj_tjjg);
		
		return statisticalDetail;
	}
	@GET
	@Path("/auto")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> pienext(@QueryParam("name")String name){
		return lxService.selectName(name);
	}
}

